home *** CD-ROM | disk | FTP | other *** search
/ Gigantic Games 2 / Gigantic Games 2.iso / pc / _b_ / battlestar / src / cypher.c < prev    next >
C/C++ Source or Header  |  1994-12-23  |  9KB  |  417 lines

  1. /*
  2.  * Copyright (c) 1983 Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that: (1) source distributions retain this entire copyright
  7.  * notice and comment, and (2) distributions including binaries display
  8.  * the following acknowledgement:  ``This product includes software
  9.  * developed by the University of California, Berkeley and its contributors''
  10.  * in the documentation or other materials provided with the distribution
  11.  * and in all advertising materials mentioning features or use of this
  12.  * software. Neither the name of the University nor the names of its
  13.  * contributors may be used to endorse or promote products derived
  14.  * from this software without specific prior written permission.
  15.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  16.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  17.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  18.  */
  19.  
  20. #ifndef lint
  21. static char sccsid[] = "@(#)cypher.c    5.3 (Berkeley) 6/1/90";
  22. #endif /* not lint */
  23.  
  24. #include "externs.h"
  25.  
  26. cypher()
  27. {
  28.     register int n;
  29.     int junk;
  30.     int lflag = -1;
  31.     char buffer[10];
  32.  
  33.     while (wordtype[wordnumber] == ADJS)
  34.         wordnumber++;
  35.     while (wordnumber <= wordcount) {
  36.         switch(wordvalue[wordnumber]) {
  37.  
  38.             case UP:
  39.                 if (location[position].access || wiz || tempwiz) {
  40.                     if (!location[position].access)
  41.                         puts("Zap!  A gust of wind lifts you up.");
  42.                     if (!move(location[position].up, AHEAD))
  43.                         return(-1);
  44.                 } else {
  45.                     puts("There is no way up");
  46.                     return(-1);
  47.                 }
  48.                 lflag = 0;
  49.                 break;
  50.  
  51.              case DOWN:
  52.                 if (!move(location[position].down, AHEAD))
  53.                     return(-1);
  54.                 lflag = 0;
  55.                 break;
  56.  
  57.              case LEFT:
  58.                 if (!move(left, LEFT))
  59.                     return(-1);
  60.                 lflag = 0;
  61.                 break;
  62.  
  63.              case RIGHT:
  64.                 if (!move(right, RIGHT))
  65.                     return(-1);
  66.                 lflag = 0;
  67.                 break;
  68.              
  69.              case AHEAD:
  70.                 if (!move(ahead, AHEAD))
  71.                     return(-1);
  72.                 lflag = 0;
  73.                 break;
  74.              
  75.              case BACK:
  76.                 if (!move(back, BACK))
  77.                     return(-1);
  78.                 lflag = 0;
  79.                 break;
  80.              
  81.              case SHOOT:
  82.                 if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
  83.                     for (n=0; n < NUMOFOBJECTS; n++)
  84.                         if (testbit(location[position].objects,n) && *objsht[n]){
  85.                             wordvalue[wordnumber+1] = n;
  86.                             wordnumber = shoot();
  87.                         }
  88.                 wordnumber++;
  89.                 wordnumber++;
  90.                 }
  91.                 else 
  92.                     shoot();
  93.                 break;
  94.  
  95.              case TAKE:
  96.                 if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
  97.                     for (n=0; n < NUMOFOBJECTS; n++)
  98.                         if (testbit(location[position].objects,n) && *objsht[n]){
  99.                             wordvalue[wordnumber+1] = n;
  100.                             wordnumber = take(location[position].objects);
  101.                         }
  102.                 wordnumber++;
  103.                 wordnumber++;
  104.                 }
  105.                 else 
  106.                     take(location[position].objects);
  107.                 break;
  108.  
  109.              case DROP:
  110.  
  111.                 if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
  112.                     for (n=0; n < NUMOFOBJECTS; n++)
  113.                         if (testbit(inven,n)){
  114.                             wordvalue[wordnumber+1] = n;
  115.                             wordnumber = drop("Dropped");
  116.                         }
  117.                 wordnumber++;
  118.                 wordnumber++;
  119.                 }
  120.                 else 
  121.                     drop("Dropped");
  122.                 break;
  123.  
  124.  
  125.              case KICK:
  126.              case THROW:
  127.                 if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
  128.                     for (n=0; n < NUMOFOBJECTS; n++)
  129.                         if (testbit(inven,n) ||
  130.                           testbit(location[position].objects, n) && *objsht[n]){
  131.                             wordvalue[wordnumber+1] = n;
  132.                             wordnumber = throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown");
  133.                         }
  134.                     wordnumber += 2;
  135.                 } else 
  136.                     throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown");
  137.                 break;
  138.  
  139.              case TAKEOFF:
  140.                 if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
  141.                     for (n=0; n < NUMOFOBJECTS; n++)
  142.                         if (testbit(wear,n)){
  143.                             wordvalue[wordnumber+1] = n;
  144.                             wordnumber = takeoff();
  145.                         }
  146.                     wordnumber += 2;
  147.                 }
  148.                 else 
  149.                     takeoff();
  150.                 break;
  151.  
  152.  
  153.              case DRAW:
  154.  
  155.                 if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
  156.                     for (n=0; n < NUMOFOBJECTS; n++)
  157.                         if (testbit(wear,n)){
  158.                             wordvalue[wordnumber+1] = n;
  159.                             wordnumber = draw();
  160.                         }
  161.                     wordnumber += 2;
  162.                 }
  163.                 else 
  164.                     draw();
  165.                 break;
  166.  
  167.  
  168.              case PUTON:
  169.  
  170.                 if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
  171.                     for (n=0; n < NUMOFOBJECTS; n++)
  172.                         if (testbit(location[position].objects,n) && *objsht[n]){
  173.                             wordvalue[wordnumber+1] = n;
  174.                             wordnumber = puton();
  175.                         }
  176.                     wordnumber += 2;
  177.                 }
  178.                 else 
  179.                     puton();
  180.                 break;
  181.  
  182.              case WEARIT:
  183.  
  184.                 if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
  185.                     for (n=0; n < NUMOFOBJECTS; n++)
  186.                         if (testbit(inven,n)){
  187.                             wordvalue[wordnumber+1] = n;
  188.                             wordnumber = wearit();
  189.                         }
  190.                     wordnumber += 2;
  191.                 }
  192.                 else 
  193.                     wearit();
  194.                 break;
  195.  
  196.  
  197.              case EAT:
  198.  
  199.                 if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){
  200.                     for (n=0; n < NUMOFOBJECTS; n++)
  201.                         if (testbit(inven,n)){
  202.                             wordvalue[wordnumber+1] = n;
  203.                             wordnumber = eat();
  204.                         }
  205.                     wordnumber += 2;
  206.                 }
  207.                 else 
  208.                     eat();
  209.                 break;
  210.  
  211.  
  212.             case PUT:
  213.                 put();
  214.                 break;
  215.  
  216.  
  217.             case INVEN:
  218.                 if (ucard(inven)){
  219.                     puts("You are holding:\n");
  220.                     for (n=0; n < NUMOFOBJECTS; n++)
  221.                         if (testbit(inven,n))
  222.                             printf("\t%s\n", objsht[n]);
  223.                     printf("\n= %d kilogram%s (%d%%)\n", carrying, (carrying == 1 ? "." : "s."),(WEIGHT ? carrying*100/WEIGHT : -1));
  224.                     printf("Your arms are %d%% full.\n",encumber*100/CUMBER);
  225.                 }
  226.                 else
  227.                     puts("You aren't carrying anything.");
  228.                     
  229.                 if (ucard(wear)){
  230.                     puts("\nYou are wearing:\n");
  231.                     for (n=0; n < NUMOFOBJECTS; n++)
  232.                         if (testbit(wear,n))
  233.                             printf("\t%s\n", objsht[n]);
  234.                 }
  235.                 else
  236.                     puts("\nYou are stark naked.");
  237.                 if (card(injuries,NUMOFINJURIES)){
  238.                     puts("\nYou have suffered:\n");
  239.                     for (n=0; n < NUMOFINJURIES; n++)
  240.                         if (injuries[n])
  241.                             printf("\t%s\n",ouch[n]);
  242.                     printf("\nYou can still carry up to %d kilogram%s\n",WEIGHT,(WEIGHT == 1 ? "." : "s."));
  243.                 }
  244.                 else
  245.                     puts("\nYou are in perfect health.");
  246.                 break;
  247.  
  248.             case USE:
  249.                 lflag = use();
  250.                 break;
  251.  
  252.             case LOOK:
  253.                 if (!notes[CANTSEE] || testbit(inven,LAMPON) || testbit(location[position].objects,LAMPON) || matchlight){
  254.                     beenthere[position] = 2;
  255.                     writedes();
  256.                     printobjs();
  257.                     if (matchlight){
  258.                         puts("\nYour match splutters out.");
  259.                         matchlight = 0;
  260.                     }
  261.                 } else 
  262.                     puts("I can't see anything.");
  263.                 return(-1);
  264.                 break;
  265.  
  266.              case SU:
  267.              if (wiz || tempwiz){
  268.                 printf("\nRoom (was %d) = ", position);
  269.                 fgets(buffer,10,stdin);
  270.                 if (*buffer != '\n')
  271.                     sscanf(buffer,"%d", &position);
  272.                 printf("Time (was %d) = ",time);
  273.                 fgets(buffer,10,stdin);
  274.                 if (*buffer != '\n')
  275.                     sscanf(buffer,"%d", &time);
  276.                 printf("Fuel (was %d) = ",fuel);
  277.                 fgets(buffer,10,stdin);
  278.                 if (*buffer != '\n')
  279.                     sscanf(buffer,"%d", &fuel);
  280.                 printf("Torps (was %d) = ",torps);
  281.                 fgets(buffer,10,stdin);
  282.                 if (*buffer != '\n')
  283.                     sscanf(buffer,"%d", &torps);
  284.                 printf("CUMBER (was %d) = ",CUMBER);
  285.                 fgets(buffer,10,stdin);
  286.                 if (*buffer != '\n')
  287.                     sscanf(buffer,"%d", &CUMBER);
  288.                 printf("WEIGHT (was %d) = ",WEIGHT);
  289.                 fgets(buffer,10,stdin);
  290.                 if (*buffer != '\n')
  291.                     sscanf(buffer,"%d",&WEIGHT);
  292.                 printf("Clock (was %d) = ",clock);
  293.                 fgets(buffer,10,stdin);
  294.                 if (*buffer != '\n')
  295.                     sscanf(buffer,"%d",&clock);
  296.                 printf("Wizard (was %d, %d) = ",wiz, tempwiz);
  297.                 fgets(buffer,10,stdin);
  298.                 if (*buffer != '\n'){
  299.                     sscanf(buffer,"%d",&junk);
  300.                     if (!junk)
  301.                         tempwiz = wiz = 0;
  302.                 }
  303.                 printf("\nDONE.\n");
  304.                 return(0);
  305.              }
  306.              else
  307.                  puts("You aren't a wizard.");
  308.              break;
  309.                 
  310.              case SCORE:
  311.                 printf("\tPLEASURE\tPOWER\t\tEGO\n");
  312.                 printf("\t%3d\t\t%3d\t\t%3d\n\n",pleasure,power,ego);
  313.                 printf("This gives you the rating of %s in %d turns.\n",rate(),time);
  314.                 printf("You have visited %d out of %d rooms this run (%d%%).\n",card(beenthere,NUMOFROOMS),NUMOFROOMS,card(beenthere,NUMOFROOMS)*100/NUMOFROOMS);
  315.                 break;
  316.  
  317.              case KNIFE:
  318.              case KILL:
  319.                 murder();
  320.                 break;
  321.  
  322.              case UNDRESS:
  323.              case RAVAGE:
  324.                 ravage();
  325.                 break;
  326.  
  327.              case SAVE:
  328.                 save();
  329.                 break;
  330.  
  331.              case FOLLOW:
  332.                 lflag = follow();
  333.                 break;
  334.  
  335.              case GIVE:
  336.                 give();
  337.                 break;
  338.  
  339.              case KISS:
  340.                 kiss();
  341.                 break;
  342.  
  343.              case LOVE:
  344.                  love();
  345.                  break;
  346.  
  347.              case RIDE:
  348.                 lflag = ride();
  349.                 break;
  350.  
  351.              case DRIVE:
  352.                 lflag = drive();
  353.                 break;
  354.  
  355.              case LIGHT:
  356.                  light();
  357.                  break;
  358.  
  359.              case LAUNCH:
  360.                 if (!launch())
  361.                     return(-1);
  362.                 else 
  363.                     lflag = 0;
  364.                 break;
  365.  
  366.             case LANDIT:
  367.                 if (!land())
  368.                     return(-1);
  369.                 else
  370.                     lflag = 0;
  371.                 break;
  372.  
  373.             case TIME:
  374.                 chime();
  375.                 break;
  376.  
  377.              case SLEEP:
  378.                 zzz();
  379.                 break;
  380.  
  381.              case DIG:
  382.                 dig();
  383.                 break;
  384.  
  385.              case JUMP:
  386.                 lflag = jump();
  387.                 break;
  388.  
  389.              case BURY:
  390.                 bury();
  391.                 break;
  392.  
  393.              case SWIM:
  394.                 puts("Surf's up!");
  395.                 break;
  396.  
  397.              case DRINK:
  398.                 drink();
  399.                 break;
  400.  
  401.              case QUIT:
  402.                 die();
  403.  
  404.              default:
  405.                 puts("How's that?");
  406.                 return(-1);
  407.                 break;
  408.  
  409.              
  410.         }
  411.         if (wordnumber < wordcount && *words[wordnumber++] == ',')
  412.             continue;
  413.         else return(lflag);
  414.        }
  415.        return(lflag);
  416. }
  417.